<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/laypage.css">
    <link rel="stylesheet" href="layui-v2.4.5/layui/css/layui.css" type="text/css"/>
    <script src="js/vue/vue.min.js"></script>
    <script src="js/jquery/jquery.min.js"></script>
    <script src="layui-v2.4.5/layui/layui.js" charset="utf-8"/>
    <script src="js/layer/layer.js" charset="utf-8"></script>
</head>
<body>
<div id="app" class="container">

    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">用户名称</label>
            <input type="text" class="form-control" id="username" placeholder="用户名称">
        </div>
        <div class="form-group">
            <label class="sr-only" for="userage">用户年龄</label>
            <input type="text" class="form-control" id="userage" placeholder="用户年龄">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询用户</button>
        <button type="button" id="addUserBtn" class="btn btn-danger">增加用户</button>
    </form>


    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>TID</td>
                <td>标题</td>
                <td>内容</td>
                <td>图片</td>
                <td></td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{item.tid}}</td>
                <td>{{index+1}}</td>
                <td>{{item.title}}</td>
                <td>{{item.context}}</td>
                <td>{{item.pic}}</td>
                <td></td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    var getTopicList = function (curr) {
        $.ajax({
            type: "get",
            url: "queryTopic",
            dataType:"json",
            data: {
                pageNum: curr || 1,
                pageSize: 3,
                title: $("#username").val()
            },
            success: function (data) {
                app.result = data.result;
                layui.use('laypage',function () {
                    var laypage=layui.laypage;

                    //执行一个laypage实例
                    laypage.render({
                        elem:'pagenav',
                        count:data.totalNum,
                        limit:data.pageSize,
                        curr:curr||1,
                        first:'首页',
                        last:'尾页',
                        jump:function (obj,first) {
                            if (!first){
                                getTopicList(obj.curr);
                            }
                        }
                    });
                });
            }
        });
    };

    getTopicList();

    $("#findUser").click(function () {
        getTopicList();
    });
</script>

</body>
</html>